package com.j180;

import com.j180.servlet.TestServlet;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8088);
        //引导tomcat 使用http引擎(这句话是必须的)
        tomcat.getConnector();
        //设置tomcat的应用上下文 contextPath：设置项目的应用的路径
        Context  context =  tomcat.addContext("/web_tomcat",null);
        //注册servlet
        Wrapper servlet = tomcat.addServlet(context,"TestServlet",new TestServlet());
        //给servlet进行映射
         servlet.addMapping("/test");
         //设置servlet在服务器启动器加载
        servlet.setLoadOnStartup(1);
         //启动服务器
        try {
            tomcat.start();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }


    }
}
